import {Component, OnInit} from '@angular/core';
import {_HttpClient} from '@delon/theme';
import {AdminService} from '../admin.service';
import {FormBuilder, FormGroup, Validators} from '@angular/forms';
import {Sysset} from '../sysset';
import {NzMessageService} from 'ng-zorro-antd';

@Component({
    selector: 'app-indexset',
    templateUrl: './indexset.component.html',
})
export class IndexsetComponent implements OnInit {

    setForm: FormGroup;
    data: Sysset = {};

    constructor(
        private adminService: AdminService,
        private fb: FormBuilder,
        private msg: NzMessageService,
    ) {
    }

    ngOnInit() {
        this.setForm = this.fb.group({
            tttraffic: ['', Validators.required],
            safetyedu: ['', Validators.required],
            devschool: ['', Validators.required],
            aboutme: ['', Validators.required],
        });
        this.adminService.getSysSet().subscribe(res => {
            this.data = res;
            this.setForm.patchValue({
                tttraffic: this.data['tttraffic'],
                safetyedu: this.data['safetyedu'],
                devschool: this.data['devschool'],
                aboutme: this.data['aboutme'],

            });
        });
    }

    save() {
        const res = this.setForm.value;
        this.data['tttraffic'] = res['tttraffic'];
        this.data['safetyedu'] = res['safetyedu'];
        this.data['devschool'] = res['devschool'];
        this.data['aboutme'] = res['aboutme'];

        this.adminService.setSysSet(this.data).subscribe(res => {
            this.msg.success('修改成功');
        }, __ => {

        });
    }

}
